import java.util.Arrays;

/**
 * @Author ZhangCuirong
 * @Date 2025/10/10 9:24
 * @description:
 */
public class Solution670 {
    public int maximumSwap(int num) {
        char[] s = String.valueOf(num).toCharArray();
        return Integer.parseInt(new String(maximum(s,0)));
    }

    public char[] maximum(char[] s, int start) {
        if (start >= s.length - 1) {
            return s;
        }
        char max = s[start];
        int maxPos = start;
        for (int i = start; i < s.length; i++) {
            if (s[i] >= max) {
                max = s[i];
                maxPos = i;
            }
        }
        if (maxPos != start&& max !=s[start]) {
            char temp = s[start];
            s[start] = s[maxPos];
            s[maxPos] = temp;
            return s;
        } else {
            return maximum(s, start + 1);
        }
    }

    public static void main(String[] args) {
        Solution670 solution = new Solution670();
        System.out.println(solution.maximumSwap(2736));
        System.out.println(solution.maximumSwap(9973));
        System.out.println(solution.maximumSwap(98368));
        System.out.println(solution.maximumSwap(1993));
    }
}
